const Util = require('../../utils/util.js');
const Api = require('../../api/api.js')
const app = getApp()

Page({
  data: {
    orderId: '',
    forpayinfo: '',
    orderInfo: '',
    sys_code: '',
    assistCheckNo: '',
    bookType: '',
    info: '',
    linkName: '',
    linkMobile:'',
    linkIdcard:'',
    occDate: '',
    orderNo: '',
    orderStatus: '',
    payStatus: '',
    outOrderNo: '',
    paySum: '',
    amount: '',
    goodsName: '',
    ticketId: ''

  },
  onLoad: function (paras) {
    this.setData({
      orderInfo: paras.orderInfo,
      // forpayinfo: paras.forpayinfo,
      ticketId: paras.ticketId
    })

    var pagethis = this
    Api.getPayInfo({
      data:app.addParams({
        "orderInfo.id": pagethis.data.orderInfo,
      }),
      success:(res) => {
        if (res.data.result == true) {
          pagethis.setData({
            orderId: res.data.data.orderInfo.id,
            amount: res.data.data.amount,
            info: res.data.data.orderInfo.info,
            paySum: res.data.data.orderInfo.paySum,
            linkName: res.data.data.orderInfo.linkName,
            linkMobile: res.data.data.orderInfo.linkMobile,
            linkIdcard: res.data.data.orderInfo.linkIdcard,
            payStatus: res.data.data.orderInfo.payStatus,
            occDate: res.data.data.orderInfo.occDate,
            goodsName: res.data.data.orderInfo.goodsName,
          })

        }
      }
    })   
  },
  goPayTap: function () {
    var pagethis = this
    Api.toWxPay({
      data:app.addParams({
        orderId: pagethis.data.orderId
      }),
      success:(rps) => {
        wx.requestPayment({
          'timeStamp': rps.data.data.timeStamp,
          'nonceStr': rps.data.data.nonceStr,
          'package': rps.data.data.packageStr,
          'signType': 'MD5',
          'paySign': rps.data.data.paySign,
          'success': function (res) {
            wx.redirectTo({
              url: '../paysuccess/paysuccess?orderId=' + pagethis.data.orderId + '&ticketId=' + pagethis.data.ticketId
            })
          },
          'fail': function (rqs) {
            wx.showModal({
              title: '支付失败',
              content: rqs.data.msg,
              success: function (rqs) {
              }
            })
          }
        })
      }
    })

  }
})